import { showFailToast } from 'vant';
import router from "@/router";
import axios from "axios";
//在头部默认添加Authorization 的token 字段
axios.defaults.headers.common['Authorization'] = localStorage.getItem('token');
//默认的BaseUrl，这样前端写代码就不用额外添加/api，
axios.defaults.baseURL='http://8.155.29.111:8080/api/'

//在收到响应后进行拦截，主要是监测 登录失败的信息
axios.interceptors.response.use((response)=>{

    const msg = response.data.msg;
    if (msg==='NOT_LOGIN'){

        showFailToast('登录异常')
        router.push("/error");//返回登录界面
        return response
    }
    return response;
})
export default axios;
